package com.aqielife.demo.config;

import com.aqelife.webflux.interfaces.ProxyCreator;
import com.aqelife.webflux.proxys.JDKProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.AsyncRestTemplate;

/**
 * @author aqie
 * @date 2022/02/05 12:05
 * @desc
 */
@Configuration
public class WebConfiguration {

  @Bean
  public AsyncRestTemplate asyncRestTemplate() {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    //设置链接超时时间
    factory.setConnectTimeout(100);
    //设置读取资料超时时间
    factory.setReadTimeout(200);
    //设置异步任务（线程不会重用，每次调用时都会重新启动一个新的线程）
    factory.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return new AsyncRestTemplate(factory);
  }



  /**
   * 创建jdk代理工具类
   *
   * @return
   */
  @Bean
  ProxyCreator jdkProxyCreator() {
    return new JDKProxyCreator();
  }



}
